package com.lucker.common.util;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class MissDataUtil {
	
	//misscode_list表里循环出来caiId对应的missTypeId和num和开奖号码和当前遗漏
    public static boolean isNumsBingGo(int missTypeId, ArrayList<Integer> firstNums,ArrayList<Integer> secondNums,ArrayList<Integer> awardNums){
        if(missTypeId==8){// 前一直选
            if(firstNums.get(0)==awardNums.get(0)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId==9){// 前二直选
            if(firstNums.get(0)==awardNums.get(0)&&firstNums.get(1)==awardNums.get(1)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId==11){// 前三直选
            if(firstNums.get(0)==awardNums.get(0)&&firstNums.get(1)==awardNums.get(1)&&firstNums.get(2)==awardNums.get(2)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId>=13&&missTypeId<=15){// 任二 单式三码四码
            if(isMissValueReset(firstNums,awardNums,2)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }

        }else if(missTypeId>=16&&missTypeId<=18){// 任二的胆拖玩法
            if(isDanTuoMissValueReset(firstNums,secondNums,awardNums,2)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId>=19&&missTypeId<=21){// 任三多码
            if(isMissValueReset(firstNums,awardNums,3)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }

        }else if(missTypeId>=22&&missTypeId<=32){// 任三的胆拖玩法
            if(isDanTuoMissValueReset(firstNums,secondNums,awardNums,3)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId>=34&&missTypeId<=37){// 任四多码
            if(isMissValueReset(firstNums,awardNums,4)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }

        }else if(missTypeId>=38&&missTypeId<=55){// 任四的胆拖玩法
            if(isDanTuoMissValueReset(firstNums,secondNums,awardNums,4)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId == 56){// 任五单式
            if(awardNums.containsAll(firstNums)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId>=57&&missTypeId<=80){// 任五的胆拖玩法
            if(isDanTuoMissValueReset(firstNums,secondNums,awardNums,5)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId==81){//任六单式
            if(firstNums.containsAll(awardNums)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId>=83&&missTypeId<=110) {// 任六的胆拖玩法
            if(isDanTuoBigMissValueReset(firstNums,secondNums,awardNums,6)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId==111){//任七单式
            if(firstNums.containsAll(awardNums)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId>=112&&missTypeId<=125) {// 任七的胆拖玩法
            if(isDanTuoBigMissValueReset(firstNums,secondNums,awardNums,7)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId==126){//任八单式
            if(firstNums.containsAll(awardNums)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId>=127&&missTypeId<=135) {// 任七的胆拖玩法
            if(isDanTuoBigMissValueReset(firstNums,secondNums,awardNums,8)){
                //该条数据当前遗漏置0
                return true;
            }else {
                //该条数据当前遗漏+1
                return false;
            }
        }else if(missTypeId>=136&&missTypeId<=146){//前二组
            ArrayList<Integer> pre2List = new ArrayList<>();
            pre2List.add(awardNums.get(0));
            pre2List.add(awardNums.get(1));
            if (missTypeId==136){
                if(firstNums.containsAll(pre2List)){
                    //该条数据当前遗漏置0
                    return true;
                }else {
                    //该条数据当前遗漏+1
                    return false;
                }
            }else {
                if(isDanTuoMissValueReset(firstNums,secondNums,pre2List,2)){
                    //该条数据当前遗漏置0
                    return true;
                }else {
                    //该条数据当前遗漏+1
                    return false;
                }
            }

        }else if(missTypeId>=147&&missTypeId<=163){//前三组
            ArrayList<Integer> pre3List = new ArrayList<>();
            pre3List.add(awardNums.get(0));
            pre3List.add(awardNums.get(1));
            pre3List.add(awardNums.get(2));
            if (missTypeId==147){
                if(firstNums.containsAll(pre3List)){
                    //该条数据当前遗漏置0
                    return true;
                }else {
                    //该条数据当前遗漏+1
                    return false;
                }
            }else {
                if(isDanTuoMissValueReset(firstNums,secondNums,pre3List,3)){
                    //该条数据当前遗漏置0
                    return true;
                }else {
                    //该条数据当前遗漏+1
                    return false;
                }
            }

        }
        return false;
        //完成之后把数据库该条数据更新掉（包括最大遗漏和近10次遗漏）
    }
    
    
    //misscode_list表里循环出来caiId对应的missTypeId和num和开奖号码和当前遗漏
    public static int calculateCurrentMissValue(int missTypeId, ArrayList<Integer> firstNums,ArrayList<Integer> secondNums,ArrayList<Integer> awardNums,int currentMissValue){
        if(missTypeId==8){// 前一直选
            if(firstNums.get(0)==awardNums.get(0)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId==9){// 前二直选
            if(firstNums.get(0)==awardNums.get(0)&&firstNums.get(1)==awardNums.get(1)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId==11){// 前三直选
            if(firstNums.get(0)==awardNums.get(0)&&firstNums.get(1)==awardNums.get(1)&&firstNums.get(2)==awardNums.get(2)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId>=13&&missTypeId<=15){// 任二 单式三码四码
            if(isMissValueReset(firstNums,awardNums,2)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }

        }else if(missTypeId>=16&&missTypeId<=18){// 任二的胆拖玩法
            if(isDanTuoMissValueReset(firstNums,secondNums,awardNums,2)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId>=19&&missTypeId<=21){// 任三多码
            if(isMissValueReset(firstNums,awardNums,3)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }

        }else if(missTypeId>=22&&missTypeId<=32){// 任三的胆拖玩法
            if(isDanTuoMissValueReset(firstNums,secondNums,awardNums,3)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId>=34&&missTypeId<=37){// 任四多码
            if(isMissValueReset(firstNums,awardNums,4)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }

        }else if(missTypeId>=38&&missTypeId<=55){// 任四的胆拖玩法
            if(isDanTuoMissValueReset(firstNums,secondNums,awardNums,4)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId == 56){// 任五单式
            if(awardNums.containsAll(firstNums)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId>=57&&missTypeId<=80){// 任五的胆拖玩法
            if(isDanTuoMissValueReset(firstNums,secondNums,awardNums,5)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId==81){//任六单式
            if(firstNums.containsAll(awardNums)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId>=83&&missTypeId<=110) {// 任六的胆拖玩法
            if(isDanTuoBigMissValueReset(firstNums,secondNums,awardNums,6)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId==111){//任七单式
            if(firstNums.containsAll(awardNums)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId>=112&&missTypeId<=125) {// 任七的胆拖玩法
            if(isDanTuoBigMissValueReset(firstNums,secondNums,awardNums,7)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId==126){//任八单式
            if(firstNums.containsAll(awardNums)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId>=127&&missTypeId<=135) {// 任七的胆拖玩法
            if(isDanTuoBigMissValueReset(firstNums,secondNums,awardNums,8)){
                //该条数据当前遗漏置0
                currentMissValue = 0;
            }else {
                //该条数据当前遗漏+1
                currentMissValue = currentMissValue+1;
            }
        }else if(missTypeId>=136&&missTypeId<=146){//前二组
            ArrayList<Integer> pre2List = new ArrayList<>();
            pre2List.add(awardNums.get(0));
            pre2List.add(awardNums.get(1));
            if (missTypeId==136){
                if(firstNums.containsAll(pre2List)){
                    //该条数据当前遗漏置0
                    currentMissValue = 0;
                }else {
                    //该条数据当前遗漏+1
                    currentMissValue = currentMissValue+1;
                }
            }else {
                if(isDanTuoMissValueReset(firstNums,secondNums,pre2List,2)){
                    //该条数据当前遗漏置0
                    currentMissValue = 0;
                }else {
                    //该条数据当前遗漏+1
                    currentMissValue = currentMissValue+1;
                }
            }

        }else if(missTypeId>=147&&missTypeId<=163){//前三组
            ArrayList<Integer> pre3List = new ArrayList<>();
            pre3List.add(awardNums.get(0));
            pre3List.add(awardNums.get(1));
            pre3List.add(awardNums.get(2));
            if (missTypeId==147){
                if(firstNums.containsAll(pre3List)){
                    //该条数据当前遗漏置0
                    currentMissValue = 0;
                }else {
                    //该条数据当前遗漏+1
                    currentMissValue = currentMissValue+1;
                }
            }else {
                if(isDanTuoMissValueReset(firstNums,secondNums,pre3List,3)){
                    //该条数据当前遗漏置0
                    currentMissValue = 0;
                }else {
                    //该条数据当前遗漏+1
                    currentMissValue = currentMissValue+1;
                }
            }

        }
        return currentMissValue;
        //完成之后把数据库该条数据更新掉（包括最大遗漏和近10次遗漏）
    }

    //任选多码玩法是否中奖 count是满足中奖条件的号码个数
    public static boolean isMissValueReset(ArrayList<Integer> firstNums,ArrayList<Integer> awardNums, int count){
    	 Set firstNumsSet = new HashSet(firstNums);
         Set awardNumsSet = new HashSet(awardNums);
         int realCount = 0;
         Iterator it = firstNumsSet.iterator();
         while (it.hasNext()){
             if(awardNumsSet.contains(it.next())){
                 realCount++;
                 if(realCount>=count){
                     return true;
                 }
             }
         }
         return false;
    }

    //任五以及任五以下任选胆拖玩法是否中奖 count是满足中奖条件的号码个数
    public static boolean isDanTuoMissValueReset(ArrayList<Integer> firstNums,ArrayList<Integer> secondNums,ArrayList<Integer> awardNums, int count){
    	Set firstNumsSet = new HashSet(firstNums);
        Set secondNumsSet = new HashSet(secondNums);
        Set awardNumsSet = new HashSet(awardNums);

        int realCount = 0;
        int firstSize = firstNums.size();
        if(awardNumsSet.containsAll(firstNumsSet)){
            Iterator it = secondNumsSet.iterator();
            while (it.hasNext()){
                if(awardNumsSet.contains(it.next())){
                    realCount++;
                    if(realCount>=count-firstSize){
                        return true;
                    }
                }
            }
            return false;
        }else {
            return false;
        }
    }

    //任六以及任六以上任选胆拖玩法是否中奖 count是玩法单注号码个数
    public static boolean isDanTuoBigMissValueReset(ArrayList<Integer> firstNums,ArrayList<Integer> secondNums,ArrayList<Integer> awardNums, int count){
    	Set firstNumsSet = new HashSet(firstNums);
        Set secondNumsSet = new HashSet(secondNums);
        Set awardNumsSet = new HashSet(awardNums);

        int realCount = 0;
        int firstSize = firstNums.size();
        if(awardNumsSet.containsAll(firstNumsSet)){
            Iterator it = secondNumsSet.iterator();
            while (it.hasNext()){
                if(awardNumsSet.contains(it.next())){
                    realCount++;
                    if(realCount>=5-firstSize){
                        return true;
                    }
                }
            }
            return false;
        }else {
            int firstRealCount=0;
            Iterator it = firstNumsSet.iterator();
            while (it.hasNext()){
                if(awardNumsSet.contains(it.next())){
                    firstRealCount++;
                }
            }
            if(count-firstSize+firstRealCount>=5){
                Iterator it_sec = secondNumsSet.iterator();
                while (it_sec.hasNext()){
                    if(awardNumsSet.contains(it_sec.next())){
                        realCount++;
                        if(realCount>=5-firstRealCount){
                            return true;
                        }
                    }
                }
                return false;
            }else {
                return false;
            }
        }
    }
    
    public static double missStatusValue(int currentMissVale, float theoryCycle, int combinationCount){
    	   return Math.pow(1-1/theoryCycle,currentMissVale)*10*combinationCount;
    }
    
}

